package org.example.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.example.assistant.FormAssitant;
import org.example.assistant.XiaozhiAgent;
import org.example.bean.ChatForm;
import org.example.bean.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "表单")
@RestController
@RequestMapping("/api/form")
public class FormController {
    @Autowired
    private FormAssitant formAssitant;

    @Operation(summary = "对话")
    @PostMapping("/chat")
    public ChatResponse chat(@RequestBody ChatForm chatForm) {
        UserChatRequestContext.reset();
        ChatResponse chatResponse = new ChatResponse();
        chatResponse.setType("Q");
        String message=formAssitant.chart(chatForm.getMemoryId(),chatForm.getMessage());
        if(StringUtils.equalsIgnoreCase(message,"生成成功")){
            System.out.println("生成json返回");
            chatResponse.setType("J");
            chatResponse.setData(UserChatRequestContext.get());
            return chatResponse;
        }
        chatResponse.setData(message);
        return chatResponse;
    }
}
